window.onload=function(){
	
	//轮播效果
	
	var runplayurl=["img/runplay1.jpg",
	"img/runplay2.jpg",
	"img/runplay3.jpg",
	"img/runplay4.jpg",
	"img/runplay5.jpg",
	"img/runplay6.jpg",
	"img/runplay7.jpg",
	"img/runplay8.jpg",
	"img/runplay9.jpg",];
	var runplayblururl=["img/runplay1blur.jpg",
	"img/runplay2blur.jpg",
	"img/runplay3blur.jpg",
	"img/runplay4blur.jpg",
	"img/runplay5blur.jpg",
	"img/runplay6blur.jpg",
	"img/runplay7blur.jpg",
	"img/runplay8blur.jpg",
	"img/runplay9blur.jpg",];
	var playingindex=0;
	var img=document.getElementById("runplay").getElementsByTagName("img")[0];
	var imgblur=document.getElementsByClassName("recommend-wrap")[0];
	var dotlist=document.getElementById("runplay").getElementsByClassName("rundot")[0].getElementsByTagName('a');
	//轮播过程
	function play(){
		dotlist[playingindex].classList.remove("choose");
		playingindex=(playingindex+1)%9;
		imgblur.style.backgroundImage="url('"+runplayblururl[playingindex]+"')";
		img.src=runplayurl[playingindex];
		dotlist[playingindex].classList.add("choose");
	}
	//开始轮播
	var playinterval;
	function startplay(){
		img.style.animationDuration="5s";
		img.style.animationName="in-out";
		img.src=runplayurl[playingindex];
		for(var i=0;i<9;i++)
		{
			dotlist[i].classList.remove("choose");
		}
		dotlist[playingindex].classList.add("choose");
		imgblur.style.backgroundImage="url('"+runplayblururl[playingindex]+"')";
		playinterval=setInterval(play,5000);
	}
	startplay();
	//停止轮播
	function restartplay(){
		clearInterval(playinterval);
		img.style.animationName="";
		img.style.animationDuration="";
		setTimeout(startplay,10);
	}
	//绑定turnleft点击事件
	var turnleft=document.getElementsByClassName("recommend")[0].getElementsByClassName("turn-left")[0];
	turnleft.onclick=function(){
		playingindex=(playingindex+8)%9;
		restartplay();
	}
	//绑定turnright点击事件
	var turnright=document.getElementsByClassName("recommend")[0].getElementsByClassName("turn-right")[0];
	turnright.onclick=function(){
		playingindex=(playingindex+1)%9;
		restartplay();
	}
	//绑定rundot点击事件
	var dotlist=document.getElementById("runplay").getElementsByClassName("rundot")[0].getElementsByTagName("a");
	for(var i=0;i<9;i++)
	{
		dotlist[i].index=i;
		dotlist[i].onclick=function(){
			playingindex=this.index;
			console.log(this.index);
			restartplay();
		}
	}
	
	//初始化hot-recomment图片
	var hotrecommentlist=document.getElementsByClassName("hot-recomment-list")[0].getElementsByClassName("sheet");
	for(var i=0;i<8;i++)
	{
		var j=i+1;
		hotrecommentlist[i].style.backgroundImage="url(img/hotrecomment"+j+".jpg)";
	}
	
	
	//绑定新碟上架的turnleft,turnright点击事件
	var new_turnleft=document.getElementsByClassName("new-album-wrap")[0].getElementsByClassName("turn-left")[0];
	var new_turnright=document.getElementsByClassName("new-album-wrap")[0].getElementsByClassName("turn-right")[0];
	var new_list=document.getElementsByClassName("new-album")[0].getElementsByClassName("album-list")[0];
	
	
	new_turnleft.onclick=function(){
		switch(new_list.style.left){
			case "-640px":
				new_list.style.animationName="new-turnleft1";
				new_list.style.left="-1280px";
				break;
			case "-1280px":
				new_list.style.animationName="new-turnleft2";
				new_list.style.left="-640px";
				break;
		}
	}
	new_turnright.onclick=function(){
		switch(new_list.style.left){
			case "-640px":
				new_list.style.animationName="new-turnright1";
				new_list.style.left="-1280px";
				break;
			case "-1280px":
				new_list.style.animationName="new-turnright2";
				new_list.style.left="-640px";
				break;
		}
	}
}
